﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class HurtSpend : RowDataBase
{
    public int Lv, Hurtspend;
}
public class HurtSpendCfg : DataCfgBase
{
    public override string GetFilePath()
    {
        string path = DirectoryPath + "HurtSpend";
        return path;
    }
    public override RowDataBase LoadDataInfo(GameDataTableParser data)
    {
        HurtSpend info = new HurtSpend();
        info.id = data.GetFieldByNameAsInt("id");
        info.Lv = data.GetFieldByNameAsInt("Hurt");
        info.Hurtspend = data.GetFieldByNameAsInt("HurtSpend");
        Debug.Log("HurtSpend" + info.Hurtspend);
        return info;
    }
    public IEnumerator LoadData()
    {
        return HotUpdateTools.ClientWWWLoad("Bytes/Spend.bytes", LoadClientByteCallBack);//先加载本地的配置文件

    }
    /// <summary>
    /// 加载服务器的大版本文件
    /// </summary>
    /// <param name="bundle"></param>
    private void LoadClientByteCallBack(WWW bundle)
    {

        if (bundle != null && bundle.size != 0)
        {

            Load(bundle.bytes);
            bundle.Dispose();
        }
    }
    private new void Load(byte[] byteData)
    {
        datas.Clear();

        using (GameDataTableParser gameDataTable = new GameDataTableParser()) //注意：一定要using()，这样才会自动调用这个类的Dispose()方法！！！！！！！
        {
            gameDataTable.ReadTableFromBytes(byteData, true);

            gameDataTable.first();
            while (!gameDataTable.eof())
            {
                RowDataBase info = LoadDataInfo(gameDataTable);
                datas.Add(info.id, info);
                gameDataTable.next();
            }
        }
        DatasSort();
    }

    public HurtSpend GetData(int id)
    {
        Debug.Log(datas.Count);
        foreach (int key in datas.Keys)
        {
            if (key == id)
                return datas[key] as HurtSpend;
        }
        return null;
    }


    public List<HurtSpend> lisAllData = new List<HurtSpend>();

    private void DatasSort()
    {
        foreach (int key in datas.Keys)
        {
            lisAllData.Add(datas[key] as HurtSpend);
            //return datas[key] as PackagingCfgRowData;
        }

        //根据time进行快速排序存入List中
        //sort(lisAllData, 0, lisAllData.Count - 1);
    }


    

    
}
